package edu.washington.ling.syntric.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import edu.washington.ling.syntric.util.LaTeXUtils;


public class TreeFileWriterLaTeX extends TreeFileWriter {

	private PrintStream pStream;
	
	public TreeFileWriterLaTeX(String path) throws IOException {
		super(path);
		try {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true, "UTF8");
		} 
		catch(UnsupportedEncodingException e) {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true);
		}
		pStream.print(LaTeXUtils.formatPreamble("Tree Output"));
		pStream.println("\\begin{enumerate}");
	}
	@Override
	public void close() {
		pStream.println("\\end{enumerate}");
		pStream.println("\\end{document}");
		pStream.close();
	}
	
	@Override
	public void writeTreeRep(TreeRepresentation tr, String id) {
		pStream.println("\\vbox{");
		String formattedID = LaTeXUtils.formatForLabel(id);
		pStream.println("\\begin{item}");
	    pStream.println(String.format("{\\bf Example:} %s", formattedID));
		LaTeXUtils.writeTreeRep(tr, pStream);
		pStream.println("\\end{item}}");
	}

}
